package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.dao.SetmealDao;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

	@Autowired
	MemberDao memberDao;

	@Autowired
	OrderDao orderDao;

	@Autowired
	SetmealDao setmealDao;

	@Override
	public Map<String, Object> getBusinessReportData() throws Exception {

		//今天日期
		String today = DateUtils.parseDate2String(DateUtils.getToday());
		//本周一日期
		String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
		//本周日日期
		String thisWeekSunday = DateUtils.parseDate2String(DateUtils.getSundayOfThisWeek());
		//本月1号日期
		String thisMonthFirstDay = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
		//本月最后一天的日期
		String thisMonthLastDay = DateUtils.parseDate2String(DateUtils.getLastDay4ThisMonth());


		/*reportDate: null,
				todayNewMember: 0,
				totalMember: 0,
				thisWeekNewMember: 0,
				thisMonthNewMember: 0,

				todayOrderNumber: 0,

				todayVisitsNumber: 0,

				thisWeekOrderNumber: 0,

				thisWeekVisitsNumber: 0,

				thisMonthOrderNumber: 0,
				thisMonthVisitsNumber: 0,*/
		String reportDate = today;
		long todayNewMember = memberDao.findCountByDate(today);

		long totalMember = memberDao.findTotalCount();

		long thisWeekNewMember = memberDao.findCountByAfterDate(thisWeekMonday);
		long thisMonthNewMember = memberDao.findCountByAfterDate(thisWeekMonday);

		long todayOrderNumber = orderDao.findCountByDate(today);

		long todayVisitsNumber = orderDao.findVisitsCountByDate(today);

		long thisWeekOrderNumber = orderDao.findCountBetweenDate(thisWeekMonday,thisWeekSunday);


		long thisWeekVisitsNumber = orderDao.findVisitsCountByAfterDate(thisWeekMonday);
		long thisMonthOrderNumber = orderDao.findCountBetweenDate(thisMonthFirstDay,thisMonthLastDay);
		long thisMonthVisitsNumber = orderDao.findVisitsCountByAfterDate(thisMonthFirstDay);


		List<Map<String,Object>> hotSetmeal = setmealDao.getHotSetmeal();


		Map<String,Object> map = new HashMap<>();
		map.put("reportDate",reportDate);
		map.put("todayNewMember",todayNewMember);
		map.put("totalMember",totalMember);
		map.put("thisWeekNewMember",thisWeekNewMember);
		map.put("thisMonthNewMember",thisMonthNewMember);
		map.put("todayOrderNumber",todayOrderNumber);
		map.put("todayVisitsNumber",todayVisitsNumber);
		map.put("thisWeekOrderNumber",thisWeekOrderNumber);
		map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
		map.put("thisMonthOrderNumber",thisMonthOrderNumber);
		map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
		map.put("hotSetmeal",hotSetmeal);

		return map;
	}
}
